package com.shengde.jinwawaforleader.model.homePage;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.shengde.jinwawaforleader.R;
import com.shengde.jinwawaforleader.network.BaseProtocol;
import com.shengde.jinwawaforleader.network.protocolbean.ProSchoolNewsList;
import com.shengde.jinwawaforleader.utils.DateUtil;

import java.util.List;

/**
 * 学校公告adapter
 * Created by Administrator on 2016/11/9 0009.
 */
public class SchoolNewAdapter extends BaseAdapter {
	Context context;
	List<ProSchoolNewsList.NoticesBean> noticesBean;
	public SchoolNewAdapter(Context context, List<ProSchoolNewsList.NoticesBean> noticesBean) {
		super();
		this.context =context;
		this.noticesBean=noticesBean;
	}

	@Override
	public int getCount() {
		return noticesBean.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(context)
					.inflate(R.layout.index_school_item, null);
			viewHolder.iv_school_item_logo = (ImageView) convertView
					.findViewById(R.id.iv_school_item_logo);
			viewHolder.tv_school_item_title = (TextView) convertView
					.findViewById(R.id.tv_school_item_title);
			viewHolder.tv_school_item_time = (TextView) convertView
					.findViewById(R.id.tv_school_item_time);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		viewHolder.tv_school_item_time.setText( DateUtil.getDate(String.valueOf(noticesBean.get(position).getLasttime())));
		viewHolder.tv_school_item_title.setText(noticesBean.get(position).getTitle());
		if (noticesBean.get(position).getPicturepath() == null||"".equals(noticesBean.get(position).getPicturepath())){
			viewHolder.iv_school_item_logo.setImageResource(R.drawable.monitor_item_bg);
		}else {
			Glide.with(context).load(BaseProtocol.IMG_BASE + noticesBean.get(position).getPicturepath()).into(viewHolder.iv_school_item_logo);

		}
		return convertView;
	}
	class ViewHolder {
		ImageView iv_school_item_logo;  //是视频的时候
		TextView tv_school_item_title; //姓名
		TextView tv_school_item_time;//发布时间
	}
}
